//
//  UserViewController.m
//  AStage_shougongke
//
//  Created by 赵磊 on 16/1/17.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "UserViewController.h"
#import "aStageHeader.pch"
@interface UserViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arr;
@end

@implementation UserViewController
- (void)viewWillAppear:(BOOL)animated
{
    [_tableView reloadData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:234 / 255.0 green:86 / 255.0 blue:81 / 255.0 alpha:1.0];
    self.navigationItem.title = @"我的";
    self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    self.arr = [NSMutableArray arrayWithObjects:@"登陆", @"清除缓存", @"夜间模式", @"修改密码", @"意见反馈", nil];
    [self.view addSubview:_tableView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    BOOL b = [[NSUserDefaults standardUserDefaults] boolForKey:@"isLogin"];
    if (b) {
        [self.arr replaceObjectAtIndex:0 withObject:@"注销"];
    } else {
        [self.arr replaceObjectAtIndex:0 withObject:@"登陆"];
    }
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.textLabel.text = _arr[indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    BOOL b = [userDefaults boolForKey:@"isLogin"];
    if (indexPath.row == 0) {
        if (b) {
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"注销成功" preferredStyle:UIAlertControllerStyleAlert];
            [self presentViewController:alert animated:YES completion:^{
                
            }];
            [self dismissViewControllerAnimated:YES completion:^{
                
            }];
            [userDefaults setBool:NO forKey:@"isLogin"];
            [_tableView reloadData];
        } else {
            LoginViewController *loginVC = [[LoginViewController alloc] init];
            [self.navigationController pushViewController:loginVC animated:YES];
        }
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
